package org.vectrics.recruiter.struts.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;

import org.apache.log4j.Category;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.vectrics.DataException;
import org.vectrics.hibernate.ThreadProperties;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.user.Interview;


public class RemoveInterviewAction extends Action {
    private static Category log = Category.getInstance(RemoveInterviewAction.class);
	public static String LOCATION_PARAM = "location";


	public ActionForward execute(ActionMapping mapping,
				 ActionForm form,
				 HttpServletRequest request,
				 HttpServletResponse response)	throws JspException {
				 	
		String interviewId = request.getParameter("id");
		if (interviewId != null) {
			Interview interview = RecruitServiceLocator.getRecruitUserService().findInterviewById(new Long(interviewId));
			try {
				RecruitServiceLocator.getRecruitUserService().removeInterview(interview);
				ThreadProperties.forcedCommit();
			}
			
			catch (DataException de) {
				log.error("DataException while removing interview", de);
				throw new JspException("DataException while removing interview", de);
			}
		}
		
		return (mapping.findForward("success"));
	}
}
